#ifndef _CLIENT_SOCKET_H_
#define _CLIENT_SOCKET_H_
#include <stdint.h>

#ifdef _WIN32
#include <winsock.h>
#pragma  comment(lib,"ws2_32.lib")
#else
#include<sys/select.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#endif
class CClientSock
{
public:
	CClientSock();
	~CClientSock();
     int Connect(const char * IP, int port,int is_tcp = 0);
	 int ConnectUrl(char * url ,int port);

	 int Reconnect();
	 int Close(int sock = -1);
	 int DisConnect();

	int SendRawData(char * buf, int buf_sz);

	int RcvData(char * buf ,int buf_sz);

	void SetTimeOut(int tmMs);
	int onSend(char* buf, uint32_t len, int& offset);
	int SendTimeOut(char* buf, uint32_t len, int time = 200);
protected:
	int socket_wait_writable(int sockfd, int timeout_ms);

protected:
	int m_sclient;

	sockaddr_in m_serAddr;
	fd_set      mFdr;
	fd_set      mFdw;
	char * m_rcv_buf;
	char * m_sbuf;
	int    m_sbuf_sz;
	char   m_ip[32];
	char   m_url[256];
	int    m_port;
	int    m_protoType;
	bool   m_connect_status;
	bool   m_bUDP;

};

#endif//_CLIENT_SOCKET_H_
